
var json={};
document.onkeydown = function(e) {
	var keynum = window.event ? e.keyCode : e.which;
	if (keynum == 13 && document.activeElement.id == "Info") {
		send();
	}
}

//将消息显示在网页上
function setMessageInnerHTML(message) {
	var InfoList=document.getElementById("InfoList");
	var Online=document.getElementById("UserList");
	json=JSON.parse(message);

	if(json.onstatus==1||json.onstatus==-1){
		var temp="",temp1="下线了！\r";
		if(json.onstatus==1)
			temp1="上线了!\r";
		for(var i =0;i< json.list.length;i++){
			temp+=json.list[i]+"\r";
		}
		InfoList.innerHTML += json.username+temp1;
		Online.innerHTML="OnLine: "+json.onlineCount+"\r"+temp;
	}else 
		InfoList.innerHTML += json.head + "\r" + json.message+"\r";
	InfoList.scrollTop = InfoList.scrollHeight ;
}

//发送消息
function send() {
	var Info = document.getElementById("Info");
	if (Info.value.length != 0)
		websocket.send(Info.value);
	window.setTimeout(function() {
		Info.value = "";
	}, 1);

}